home *** CD-ROM | disk | FTP | other *** search
- #! /bin/sh
- # This is a shell archive, meaning:
- # 1. Remove everything above the #! /bin/sh line.
- # 2. Save the resulting text in a file.
- # 3. Execute the file with /bin/sh (not csh) to create:
- # COPYING
- # README
- # go.ps
- # makefile
- # partie.l
- # partie.y
- # This archive created: Sat Mar 21 11:42:18 1992
- export PATH; PATH=/bin:/usr/bin:$PATH
- if test -f 'COPYING'
- then
- echo shar: "will not over-write existing file 'COPYING'"
- else
- cat << \SHAR_EOF > 'COPYING'
-
- GNU GENERAL PUBLIC LICENSE
- Version 1, February 1989
-
- Copyright (C) 1989 Free Software Foundation, Inc.
- 675 Mass Ave, Cambridge, MA 02139, USA
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
- Preamble
-
- The license agreements of most software companies try to keep users
- at the mercy of those companies. By contrast, our General Public
- License is intended to guarantee your freedom to share and change free
- software--to make sure the software is free for all its users. The
- General Public License applies to the Free Software Foundation's
- software and to any other program whose authors commit to using it.
- You can use it for your programs, too.
-
- When we speak of free software, we are referring to freedom, not
- price. Specifically, the General Public License is designed to make
- sure that you have the freedom to give away or sell copies of free
- software, that you receive source code or can get it if you want it,
- that you can change the software or use pieces of it in new free
- programs; and that you know you can do these things.
-
- To protect your rights, we need to make restrictions that forbid
- anyone to deny you these rights or to ask you to surrender the rights.
- These restrictions translate to certain responsibilities for you if you
- distribute copies of the software, or if you modify it.
-
- For example, if you distribute copies of a such a program, whether
- gratis or for a fee, you must give the recipients all the rights that
- you have. You must make sure that they, too, receive or can get the
- source code. And you must tell them their rights.
-
- We protect your rights with two steps: (1) copyright the software, and
- (2) offer you this license which gives you legal permission to copy,
- distribute and/or modify the software.
-
- Also, for each author's protection and ours, we want to make certain
- that everyone understands that there is no warranty for this free
- software. If the software is modified by someone else and passed on, we
- want its recipients to know that what they have is not the original, so
- that any problems introduced by others will not reflect on the original
- authors' reputations.
-
- The precise terms and conditions for copying, distribution and
- modification follow.
-
- GNU GENERAL PUBLIC LICENSE
- TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-
- 0. This License Agreement applies to any program or other work which
- contains a notice placed by the copyright holder saying it may be
- distributed under the terms of this General Public License. The
- "Program", below, refers to any such program or work, and a "work based
- on the Program" means either the Program or any work containing the
- Program or a portion of it, either verbatim or with modifications. Each
- licensee is addressed as "you".
-
- 1. You may copy and distribute verbatim copies of the Program's source
- code as you receive it, in any medium, provided that you conspicuously and
- appropriately publish on each copy an appropriate copyright notice and
- disclaimer of warranty; keep intact all the notices that refer to this
- General Public License and to the absence of any warranty; and give any
- other recipients of the Program a copy of this General Public License
- along with the Program. You may charge a fee for the physical act of
- transferring a copy.
-
- 2. You may modify your copy or copies of the Program or any portion of
- it, and copy and distribute such modifications under the terms of Paragraph
- 1 above, provided that you also do the following:
-
- a) cause the modified files to carry prominent notices stating that
- you changed the files and the date of any change; and
-
- b) cause the whole of any work that you distribute or publish, that
- in whole or in part contains the Program or any part thereof, either
- with or without modifications, to be licensed at no charge to all
- third parties under the terms of this General Public License (except
- that you may choose to grant warranty protection to some or all
- third parties, at your option).
-
- c) If the modified program normally reads commands interactively when
- run, you must cause it, when started running for such interactive use
- in the simplest and most usual way, to print or display an
- announcement including an appropriate copyright notice and a notice
- that there is no warranty (or else, saying that you provide a
- warranty) and that users may redistribute the program under these
- conditions, and telling the user how to view a copy of this General
- Public License.
-
- d) You may charge a fee for the physical act of transferring a
- copy, and you may at your option offer warranty protection in
- exchange for a fee.
-
- Mere aggregation of another independent work with the Program (or its
- derivative) on a volume of a storage or distribution medium does not bring
- the other work under the scope of these terms.
-
- 3. You may copy and distribute the Program (or a portion or derivative of
- it, under Paragraph 2) in object code or executable form under the terms of
- Paragraphs 1 and 2 above provided that you also do one of the following:
-
- a) accompany it with the complete corresponding machine-readable
- source code, which must be distributed under the terms of
- Paragraphs 1 and 2 above; or,
-
- b) accompany it with a written offer, valid for at least three
- years, to give any third party free (except for a nominal charge
- for the cost of distribution) a complete machine-readable copy of the
- corresponding source code, to be distributed under the terms of
- Paragraphs 1 and 2 above; or,
-
- c) accompany it with the information you received as to where the
- corresponding source code may be obtained. (This alternative is
- allowed only for noncommercial distribution and only if you
- received the program in object code or executable form alone.)
-
- Source code for a work means the preferred form of the work for making
- modifications to it. For an executable file, complete source code means
- all the source code for all modules it contains; but, as a special
- exception, it need not include source code for modules which are standard
- libraries that accompany the operating system on which the executable
- file runs, or for standard header files or definitions files that
- accompany that operating system.
-
- 4. You may not copy, modify, sublicense, distribute or transfer the
- Program except as expressly provided under this General Public License.
- Any attempt otherwise to copy, modify, sublicense, distribute or transfer
- the Program is void, and will automatically terminate your rights to use
- the Program under this License. However, parties who have received
- copies, or rights to use copies, from you under this General Public
- License will not have their licenses terminated so long as such parties
- remain in full compliance.
-
- 5. By copying, distributing or modifying the Program (or any work based
- on the Program) you indicate your acceptance of this license to do so,
- and all its terms and conditions.
-
- 6. Each time you redistribute the Program (or any work based on the
- Program), the recipient automatically receives a license from the original
- licensor to copy, distribute or modify the Program subject to these
- terms and conditions. You may not impose any further restrictions on the
- recipients' exercise of the rights granted herein.
-
- 7. The Free Software Foundation may publish revised and/or new versions
- of the General Public License from time to time. Such new versions will
- be similar in spirit to the present version, but may differ in detail to
- address new problems or concerns.
-
- Each version is given a distinguishing version number. If the Program
- specifies a version number of the license which applies to it and "any
- later version", you have the option of following the terms and conditions
- either of that version or of any later version published by the Free
- Software Foundation. If the Program does not specify a version number of
- the license, you may choose any version ever published by the Free Software
- Foundation.
-
- 8. If you wish to incorporate parts of the Program into other free
- programs whose distribution conditions are different, write to the author
- to ask for permission. For software which is copyrighted by the Free
- Software Foundation, write to the Free Software Foundation; we sometimes
- make exceptions for this. Our decision will be guided by the two goals
- of preserving the free status of all derivatives of our free software and
- of promoting the sharing and reuse of software generally.
-
- NO WARRANTY
-
- 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
- FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
- OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
- PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
- OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
- TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
- PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
- REPAIR OR CORRECTION.
-
- 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
- WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
- REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
- INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
- OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
- TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
- YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
- PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
- POSSIBILITY OF SUCH DAMAGES.
-
- END OF TERMS AND CONDITIONS
- SHAR_EOF
- fi
- if test -f 'README'
- then
- echo shar: "will not over-write existing file 'README'"
- else
- cat << \SHAR_EOF > 'README'
-
- Here comes the program to convert go games in the mgt format to
- a postscript program. I looked in the archive in september 1990
- and found nothing to do the same job.
-
- I used this program to convert the games of Shusaku and Go Seigen
- stored in the archive. All went well, except for a few files which
- contained what i supposed being typing errors not recognized by
- mgt.
-
- The postcript programming style is definitely poor, when seeing
- what is recommended by the green book.
-
- If you want to make modifications to the program, it would be nice
- to send them to me. It is heavily commented ; that will be useful
- for those who speak french.
-
- Jean Mehat.
-
-
-
- ------------
-
- To use this program on a unix system, type
- make
- to compile the program.
-
- Then run with
- mgt2ps < inputfile > outputfile.ps
-
- SHAR_EOF
- fi
- if test -f 'go.ps'
- then
- echo shar: "will not over-write existing file 'go.ps'"
- else
- cat << \SHAR_EOF > 'go.ps'
- %!PS-Adobe-1.0
- %%Creator: mgt2ps
- %%Title: une partie de go
- %%Pages: (atend)
- %%DomumentFonts: Times-Roman
- %%EndComments
-
- % Afficher un goban, avec son titre, ses recouvrements, ses kos,
- % ses commentaires, comme produit par mgt2ps
- % jm, octobre 1990
- % (c) Jean Mehat, Octobre 1990
- % De'partement d'informatique, universite de Paris 8, 2 rue de la liberte,
- % St Denis, 93526 cedex 02, France
- % jm@aristote.univ-paris8.fr ou
- % jm@geocub.greco-prog.fr
- %
- % This program is free software; you can redistribute it and/or modify
- % it under the terms of the GNU General Public License as published by
- % the Free Software Foundation; either version 1, or (at your option)
- % any later version.
- %
- % This program is distributed in the hope that it will be useful,
- % but WITHOUT ANY WARRANTY; without even the implied warranty of
- % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- % GNU General Public License for more details.
- %
- % You should have received a copy of the GNU General Public License
- % along with this program; if not, write to the Free Software
- % Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
- % decembre 1990 : re-ecrit centrer pour qu'il mesure vraiment les caracteres
- % qu'il centre
-
- % la taille du goban
- /gobantaille 19 def % taille du goban
- /h1 4 def % h1, h2, h3 : les hoshis
- /h2 gobantaille 1 add h1 sub def
- /h3 gobantaille 1 add 2 div def
-
- % le dessin du goban
- /epaisseur 1 def % epaisseur du trait du goban
- /vespace 22 def % ecart entre les traits vertical et horizontal
- /hespace 20 def
-
- % le dessin des pierres
- /prayon hespace 1 sub 2 div def % rayon d'une pierre : (hespace-1)/2
- % fonte pour etiqueter les pierres
- /eticar /Times-Roman findfont prayon scalefont def
-
- % l'e'criture des notes et commentaires
- /noteEchelle 12 def % echelle de la fonte
- % fonte pour commenter les coups
- /notecar /Times-Roman findfont noteEchelle scalefont def
- /notespace prayon dup 2 add add def
- /pierrechelle % echelle pour avoir une pierre de meme taille
- % que du texte
- noteEchelle prayon dup add div
- def
-
- % dessiner des pierres (en 0 0) : noire00, blanche00
- /noire00
- { 0 setgray newpath 0 0 prayon 0 360 arc fill
- } def
- /blanche00
- { newpath 0 0 prayon 0 360 arc
- gsave 1 setgray fill grestore 0 setgray stroke
- } def
-
- % dessiner un goban
- /goban00 {
- epaisseur setlinewidth
- newpath
- 1 1 gobantaille {
- dup dup dup % i i i i
- 1 goban2coord moveto % i i i
- gobantaille goban2coord lineto % i i
- 1 exch goban2coord moveto % i
- gobantaille exch goban2coord lineto
- } for
- stroke
-
- newpath
- [ h1 h2 h3 ]
- { % n
- dup dup % n n n
- [ h1 h2 h3 ] { % --- n m
- goban2coord % --- x y
- 2 copy moveto
- 3 0 360 arc
- } forall
- } forall
- fill
- } def
-
-
- /centrer % (nom) -> (nom) mais il a fait un moveto, (nom) sera centre
- {
- gsave
- newpath 0 0 moveto dup true charpath flattenpath pathbbox
- % (nom) xmin ymin xmax ymax
- 2 index sub % (nom) xmin ymin xmax haut
- exch 3 index sub % (nom) xmin ymin haut large
- % (nom) xmin ymin -large/2 -haut/2
- 2 div neg exch 2 div neg
- grestore
- moveto % (nom) xmin ymin
- pop pop % (nom)
- } def
-
- /tpierre { % (nom) couleur -> - ; affiche une pierre a la show
- gsave
- currentpoint translate
- 1 prayon add noteEchelle 2 div translate
- 2 eq { noire00 1 } { blanche00 0 } ifelse
- setgray eticar setfont centrer show
- grestore
- prayon dup add 2 add 0 rmoveto % deplace le point courant a la show
- } def
-
- % parametrer l'organisation de la page
- /Mg 50 def % marges gauche et droite
- /Md 8.5 72 mul Mg Mg add sub def
- /Mb 1 72 mul def % marges basses et hautes
- /Mh 11 72 mul Mb sub def
-
- /initHaut {
- /hautx Mg def % le plus haut point courant a utiliser
- /hauty Mh def % (modifie par titre et utilise par goban)
- } def
-
- /goban {
- /gobanx hautx def % coordonne'es du goban
- /gobany hauty vespace gobantaille mul sub def
- goban00
- % coord. des reprises : "12 en 5"
- /couvrex gobanx hespace gobantaille 1 add mul add def
- /couvrey gobany vespace gobantaille 2 sub mul add def
- % coordonne'es des commentaires et, si
- /comx gobanx def % il faut, des kos : "12, 15, 17 en 5"
- /comy gobany notespace 2 mul sub def
- } def
-
- /goban2coord % n m -> x y
- {
- exch
- 1 sub exch gobantaille exch sub % x-1 gobantaille-y
- vespace mul exch hespace mul exch % (x-1)hespace (gbt-y)vespace
- gobany add exch gobanx add exch % (x-1)hespace+gobanx (gbt-y)vespace+gobany
- } def
-
- % justification a la hache : on pose les mots, si on a depasse la
- % marge droite, on va a la ligne, si on a depasse la marge basse
- % on passe a la ligne suivante
- /lignespace notespace def % espace entre deux lignes
-
- /addpierre { % (nom) couleur ->
- tpierre
- currentpoint pop % (n) c x
- Md gt { comalaligne } if
- } def
-
- /addchaine { % string ->
- ( ) search % post match pre true OU string false
- { addmot show addchaine } { addmot } ifelse
- } def
-
- /addmot { % mot ->
- show % mot
- currentpoint pop % mot w+y
- Md gt { comalaligne } if
- } def
-
- /comalaligne {
- /comy comy lignespace sub def
- comy Mb le { showpage /comy Mh def } if
- comx comy moveto
- } def
-
- %
- % titres traite un tableau de chaines qui servent de titre
- % coups traite un tableau de coups ( = [nom) couleur ligne col ])
- % couvres ... un tableau de pierres qui en recouvrent d'autres :
- % ( = [(sous) couleur [ (sur) couleur ]])
- % kos ... un tableau de liste de pierres qui en recouvrent d'autres
- % ( = [(sous) c [ (sur1) c1 (sur2) c2 ... ]])
- % commentaires ... un tableau de commentaires ( = [ (nom) couleur (comm) ] )
- %
-
- /titres % [ (chaine) (chaine) ... ]
- { initHaut
- {
- hautx hauty moveto notecar setfont show
- /hauty hauty noteEchelle sub def
- } forall
- } def
-
- /coups % [ [ (nom) coul n m ] [ (nom) coul n m ] ... ]
- { { % --- [ (nom) coul n m ]
- aload pop % --- (nom) coul n m
- gsave
- goban2coord translate
- 2 eq { noire00 1 } { blanche00 0 } ifelse
- setgray eticar setfont centrer show
- grestore
- } forall
- } def
-
- /couvres % [ [ (sous) couleur [ (sur) couleur ] ] --- ]
- {
- gsave
- couvrex couvrey moveto
- { % --- [ (sous) c [ (sur) c ]]
- aload pop % --- (sous) c [ (sur) c ]
- aload pop % --- (sous) c (sur) c
- tpierre ( en ) show tpierre
- couvrex couvrey notespace sub dup /couvrey exch def
- moveto
- } forall
- /couvrey couvrey notespace sub def
- grestore
- } def
-
- /kos { % [[ko] [ko] ...]
- comx comy moveto
- lignespace notespace def
- { % ... ko=[(nom) couleur [(nom) couleur ... ]]
- aload pop % (sous) c [coups]
- true exch % (sous) c flag [coups]
- {
- exch % (sous) c (nom) true
- % ou bien (nom) c false
- { false } { addpierre true } ifelse
- } forall
- pop % (sous) c
- ( en ) addchaine
- addpierre
- comalaligne
- } forall
- comalaligne
- } def
-
- /commentaires % [ [ (nom) couleur (commentaire) ] --- ]
- {
- comx comy moveto
- lignespace noteEchelle def
- { aload pop % -> (n) couleur (com)
- 3 1 roll % -> (com) (n) couleur
- dup dup % -> (com) (n) couleur couleur couleur
- 1 eq % -> (com) (n) couleur couleur bool
- exch % -> (com) (n) couleur bool couleur
- 2 eq % -> (com) (n) couleur bool bool
- or { pierrechelle dup scale
- addpierre
- 1 pierrechelle div dup scale
- ( ) show
- } { pop pop } ifelse % com
- % or { addpierre ( ) show } { pop pop } ifelse
- addchaine % ->
- comalaligne
- } forall
- } def
-
- %%EndProlog
- SHAR_EOF
- fi
- if test -f 'makefile'
- then
- echo shar: "will not over-write existing file 'makefile'"
- else
- cat << \SHAR_EOF > 'makefile'
- #
- # mgt2ps : traduit une partie note'e dans le format mgt en programme postscript
- #
- # (c) Jean Mehat, Octobre 1990
- # De'partement d'informatique, universite de Paris 8, 2 rue de la liberte,
- # St Denis, 93526 cedex 02, France
- # jm@aristote.univ-paris8.fr ou
- # jm@geocub.greco-prog.fr
- #
- # This program is free software; you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation; either version 1, or (at your option)
- # any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with this program; if not, write to the Free Software
- # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- #
- CC = gcc
- CFLAGS = -g -O -o mgt2ps
- BINDIR = /usr/local/bin
- PSLIBDIR = `pwd`
-
- mgt2ps : partie.tab.c lex.yy.c
- $(CC) $(CFLAGS) -DYYDEBUG -DPSFILE=\"$(PSLIBDIR)/go.ps\" partie.tab.c
-
- clean :
- rm -f partie.tab.c lex.yy.c *.o a.out core *~
-
-
- lex.yy.c : partie.l
- flex partie.l
-
- partie.tab.c : partie.y
- bison partie.y
-
- install: mgt2ps
- mv mgt2ps $(BINDIR)/mgt2ps
- SHAR_EOF
- fi
- if test -f 'partie.l'
- then
- echo shar: "will not over-write existing file 'partie.l'"
- else
- cat << \SHAR_EOF > 'partie.l'
- /* partie.l
- decouper un fichier mgt en lexemes
-
- (c) Jean Mehat, Octobre 1990
- De'partement d'Informatique, Universite de Paris 8, 2 rue de la liberte,
- St Denis, 93526, Cedex 02, France
- jm@geocub.greco-prog.fr
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 1, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
- int lino = 1;
- PASDECROCHETFERMANT ([^\][])
- %%
- Name { return NAME; }
- PLayer { return PLAYER; }
- GaMe { return GAME; }
- Si[zZ]e { return SIZE; }
- VieW { return VIEW; }
- WhiteSpec { return WHITESPEC; }
- BlackSpec { return BLACKSPEC; }
- PlaCe { return PLACE; }
- DaTe { return DATE; }
- FileFormat { return FILEFORMAT; }
- GameName { return GAMENAME; }
- K[oO] { return KO; }
- AddBlack { return ADDBLACK; }
- AddWhite { return ADDWHITE; }
- AddEmpty { return ADDEMPTY; }
- Letter { return LETTER; }
- Mark { return MARK; }
- Comment { return COMMENT; }
- Black { return BLACK; }
- White { return WHITE; }
- "[" { /* Pour les args, c'est la merde parce qu'on a parfois des \[ et \]
- et parfois des [] imbrique's ; il faut escaper ( et ) */
- static char * monarg = 0;
- static int place = 0;
- int nivo, prev, c;
- int i;
- static int input(); /* pour eviter un warning de gcc */
-
- if (monarg == 0 && (monarg = (char *)calloc(place = 1024, 1)) == 0)
- merror();
-
- for(nivo = i = 0;;){
- c = input();
- /* on s'arrete ? */
- if (c == ']' && (i == 0 || monarg[i - 1] != '\\') && nivo == 0)
- break;
- /* allouew ou realloue si necessaire */
- if (i >= place - 1
- && (monarg = (char *)realloc(monarg, place += 1024)) == 0)
- merror();
- /* compte les returns */
- if (c == '\n')
- lino += 1;
- /* transforme les () en \(\)*/
- if ((c == '(' || c == ')') && (i == 0 || monarg[i - 1] != '\\'))
- monarg[i++] = '\\';
- /* compte les [] sans \,
- transforme les en \[\]*/
- if ((c == '[' || c == ']') && (i == 0 || monarg[i - 1] != '\\')){
- if (c == '[')
- nivo += 1;
- else if (c == ']')
- nivo -= 1;
- monarg[i++] = '\\';
- }
- /* maintenant, ajoute le caractere */
- monarg[i++] = c;
- }
- monarg[i] = 0;
- yylval.pcar = monarg;
- return ARG;
- }
- [;()] { return yytext[0]; }
- [ \t] ;
- \n { lino += 1; }
- . { extern char * file; printf("%s:%d: %c\n",
- file, lino, yytext[0]); }
- %%
- SHAR_EOF
- fi
- if test -f 'partie.y'
- then
- echo shar: "will not over-write existing file 'partie.y'"
- else
- cat << \SHAR_EOF > 'partie.y'
- /* partie.y -- comvertit du format mgt (Smart Go ?) en postscript
-
- (c) Jean Mehat, Octobre 1990
- De'partement d'informatique, universite de Paris 8, 2 rue de la liberte,
- St Denis, 93526 cedex 02, France
- jm@aristote.univ-paris8.fr ou
- jm@geocub.greco-prog.fr
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 1, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
- /*
- En general, convertit le format mgt (Smart Go ?) en suite de commandes
- postscript. Quoiqu'en dise main, ca ne marche qu'avec 0 ou 1 partie (le
- probleme est peut etre dans l'input() de flex ?
- jm, octobre&novembre 1990
- 7 novembre 90 : affiche aussi les pierres de handicap
- 12 novembre 90 : affiche le goban et les pierres sur la meme page,
- meme s'il y a beaucoup de kos. Libere la memoire des kos.
- */
- %token GAME SIZE VIEW BLACKSPEC WHITESPEC FILEFORMAT GAMENAME KO PLACE
- %token DATE LETTER NAME PLAYER
- %token ADDEMPTY MARK ADDBLACK ADDWHITE
- %token COMMENT WHITE BLACK
-
- %token <pcar> ARG
-
- %union {
- char * pcar;
- struct noeud *n;
- }
-
- %type <n> coup liste variante
-
- %{
- # include <assert.h>
-
- # define BLANC 1
- # define NOIR 2
-
- # define VARIANTE 1
- # define COUP 2
- # define HANDICAP 3
-
- # define GOBAN 19
-
- typedef struct point { int x, y; } Point;
-
- typedef struct noeud {
- int flag;
- struct noeud * next;
- struct noeud * fils;
- char * commentaire;
- int couleur;
- Point position;
- int numcoup;
- int ndessus;
- struct noeud * dessous;
- } Noeud;
- /* gcc les fera inline */
- static Point Pt(a, b){ Point p; p.x = a; p.y = b; return p; }
- static Noeud * courant;
- static Noeud * nouvo(){ Noeud * n;
- if ((n = (Noeud *)calloc(1, sizeof n[0])) == 0)
- merror();
- return courant = n;
- }
- static void ancien(n) Noeud *n; {
- if (n->commentaire != 0)
- free(n->commentaire);
- if (n->fils != 0)
- ancien(n->fils);
- if (n->next != 0)
- ancien(n->next);
- free(n);
- }
- static char * interne(s) char * s; { char * d;
- if ((d = (char *)malloc(strlen(s) + 1)) == 0)
- merror();
- else
- strcpy(d, s);
- return d;
- }
-
-
- Noeud * racine; /* On trouve la partie parse'e ici */
- %}
-
- %%
- racine : '(' ';'
- { $<n>$ = nouvo(); }
- props1 liste ')'
- { racine = $<n>3;
- racine->next = $5;
- }
- ;
-
- variante
- : '(' liste ')'
- { $$ = nouvo();
- $$->flag = VARIANTE;
- $$->fils = $2;
- }
- ;
-
- liste : coup liste
- { goto chainer; }
- | coup
- | variante liste
- { chainer:
- $1->next = $2;
- $$ = $1;
- }
- | variante
- ;
-
- coup : ';'
- { $<n>$ = nouvo(); }
- props
- { $$ = $<n>2;
- $$->flag = COUP;
- }
- ;
-
- props : prop props
- | /* rien */
- ;
-
- prop : GAME ARG
- | PLAYER ARG
- | KO ARG
- | MARK liste_arg
- | ADDBLACK liste_arg
- { noparse(); }
- | ADDWHITE liste_arg
- { noparse(); }
- | ADDEMPTY liste_arg
- { noparse(); }
- | LETTER liste_arg
- | COMMENT ARG
- { courant->commentaire = interne($2); }
- | WHITE ARG
- { courant->couleur = BLANC;
- addcourant:
- assert($2[0] >= 'a' && $2[0] <= 's'
- && $2[1] >= 'a' && $2[1] <= 's'
- && $2[2] == 0);
- courant->position = Pt($2[0] - 'a' + 1, $2[1] - 'a' + 1);
- }
- | BLACK ARG
- { courant->couleur = NOIR;
- goto addcourant;
- }
- | NAME ARG
- ;
-
- /* Les proprietes qu'on ne trouve que sur le premier noeud */
- props1 : prop1 props1
- | prop props1
- | /* rien */
- ;
- prop1 : SIZE ARG
- | PLACE ARG
- | DATE ARG
- | FILEFORMAT ARG
- | GAMENAME ARG
- | VIEW ARG
- | BLACKSPEC ARG
- | WHITESPEC ARG
- ;
-
- liste_arg
- : ARG liste_arg
- { ; }
- | ARG
- { ; }
- ;
- %%
- tfaire(courant, s) Noeud * courant; char * s; {
- courant->position = Pt(s[0] - 'a' + 1, s[1] - 'a' + 1);
- }
-
- # include "lex.yy.c"
- # include <ctype.h>
-
- # ifndef PSFILE
- # define PSFILE "go.ps"
- # endif
-
- char * file = "stdin";
-
- main(ac, av)
- char * av[];
- {
- int compte = 1;
- void arbre2ps();
-
- { /* d'abord la preface PostScript */
- char * filenom = PSFILE;
- FILE * file;
- char t[1024];
-
- if ((file = fopen(filenom, "r")) == 0){
- perror(filenom);
- exit(0);
- }
- while((compte = fread(t, sizeof t[0], sizeof t, file)) > 0)
- fwrite(t, sizeof t[0], compte, stdout);
- if (compte != 0)
- perror(filenom);
- }
- /* parser les args ou stdin */
- if (ac == 1){
- if (yyparse() == 0){
- arbre2ps(racine);
- ancien(racine);
- }
- } else
- for(compte = 0; --ac > 0; compte += 1)
- if (strcmp((++ av)[0], "-") != 0 && freopen(av[0], "r", stdin) != NULL){
- file = av[0];
- lino = 1;
- if (yyparse() == 0){
- arbre2ps(racine);
- ancien(racine);
- }
- } else
- perror(av[0]);
- psfinir(compte);
- }
-
- yyerror(){
- fprintf(stderr, "%s:%d: le parseur a un probleme avec %s\n",
- file, lino, yytext);
- }
- noparse(){
- fprintf(stderr, "%s:%d: je ne parse pas %s\n", file, lino, yytext);
- }
- merror(){
- fprintf(stderr, "Plus de memoire\n");
- }
-
- /* strcherche -- brutal, mais c'est fait une seule fois par partie */
- static char * strcherche(modele, texte) char * modele, * texte; {
- int i, lm, lt;
-
- lm = strlen(modele);
- lt = strlen(texte);
- if (lm > lt)
- return 0;
- else {
- for(i = 0; texte[i + lm] != 0; i += 1)
- if (strncmp(modele, &texte[i], lm) == 0)
- return & texte[i];
- return strcmp(modele, & texte[i]) == 0 ? & texte[i] : 0;
- }
- }
-
- int nnoeud, ncoup, nvariante, ncommentaire;
- /* compter -- compter et nmeroter coups et variantes */
- void compter(n) Noeud * n; {
- nnoeud += 1;
- n->numcoup = (ncoup += (n->couleur == BLANC || n->couleur == NOIR));
- nvariante += (n->flag == VARIANTE);
- ncommentaire += (n->commentaire != 0);
- }
-
- /* handicap_compter -- ajouter les pierres de handicap et les compter */
- void handicap_compter(n) Noeud * n; {
- char * p;
-
- if (n->commentaire && (p = strcherche("Handicap: ", n->commentaire)) != 0){
- int npierres = atoi(p + strlen("Handicap: "));
- static int huit[][2] = { { 16, 4}, { 4, 16}, { 16, 16}, { 4, 4},
- { 16, 10}, { 4, 10}, { 10, 16}, { 10, 4} };
- static int cinq[][2] = { { 10, 10} };
- int i;
-
- if (npierres > 9 || npierres < 0)
- fprintf(stderr, "%d pierres de handicap : je ne sais pas les poser\n", npierres);
- if (npierres > 4 && npierres % 2 == 1){
- ajoute_pierre(n, cinq[0][0], cinq[0][1]);
- npierres -= 1;
- }
- for(i = 1; i <= npierres && i <= sizeof huit / sizeof huit[0]; i += 1)
- ajoute_pierre(n, huit[i - 1][0], huit[i - 1][1]);
- }
- }
- ajoute_pierre(r, n, m) Noeud * r; int n, m; {
- Noeud * x;
-
- ncoup += 1;
- x = nouvo();
- x->flag = HANDICAP;
- x->numcoup = 0;
- x->position = Pt(n, m);
- x->couleur = NOIR;
-
- x->next = r->next;
- r->next = x;
- }
-
- Noeud * pose[1+GOBAN][1+GOBAN];
- int ndessus;
- int ndessous;
- int maxdessus;
-
- /* couvrir -- marque, pour chaque pierre, celle qui est dessous, combien elle en a dessus */
- void couvrir(n) Noeud * n; {
- if (n->flag == HANDICAP){
- assert(pose[n->position.x][n->position.y] == 0);
- pose[n->position.x][n->position.y] = n;
- } else
- if (n->couleur == BLANC || n->couleur == NOIR)
- if (pose[n->position.x][n->position.y] == 0)
- pose[n->position.x][n->position.y] = n;
- else {
- ndessus += 1;
- n->dessous = pose[n->position.x][n->position.y];
- if ((n->dessous->ndessus += 1) > maxdessus)
- maxdessus = n->dessous->ndessus;
- if (n->dessous->ndessus == 1)
- ndessous += 1;
- }
- }
- /* handicap_couvrir -- numerote *negativement* les pierres de handicap recouvertes */
- handicap_couvrir(n) Noeud * n; {
- int compte = -1;
-
- for(n = n->next; n->flag == HANDICAP; n = n->next)
- if (n->ndessus != 0)
- n->numcoup = compte--;
- }
-
-
- /* nomme -- renvoie le nom d'un coup sous forme de char *, a utiliser vite */
- char * nomme(n) Noeud * n; {
- # define MAXNOMME 4 /* apres on ecrase */
- static char noms[MAXNOMME][4];
- static int inoms = 0;;
-
- assert(n->couleur == BLANC || n->couleur == NOIR);
-
- inoms %= MAXNOMME;
- if (n->numcoup > 0)
- sprintf(noms[inoms], "%d", n->numcoup);
- else if (n->numcoup < 0)
- sprintf(noms[inoms], "%c", 'a' - (n->numcoup + 1));
- else
- noms[inoms][0] = 0;
-
- return noms[inoms++];
- }
-
- /* applique -- applique la fonction f au noeud, a son fils, au suivant */
- void applique(n, f) Noeud * n; void (*f)(); {
- f(n);
- if (n->fils != 0)
- applique(n->fils, f);
- if (n->next != 0)
- applique(n->next, f);
- }
-
- static int npages;
-
- /* arbre2ps -- traduit l'arbre de coups en p*stscript */
- void
- arbre2ps(n)
- Noeud * n;
- {
- int pscouvre(), pscoups(), pscommentaires(), koprep();
-
- /* compte noeuds, coups et variantes */
- nnoeud = ncoup = nvariante = 0;
- applique(n, compter);
- handicap_compter(n);
- printf("%% %d noeuds, %d coups, %d variantes %d commentaires\n",
- nnoeud, ncoup, nvariante, ncommentaire);
- if (nvariante > 0)
- printf("%% Il y a %d variantes; je ne sais pas traiter les variantes\n",
- nvariante);
- /* compte les recouvrements */
- { int i, j;
-
- for(i = 1; i <= GOBAN; i += 1)
- for(j = 1; j < GOBAN; j += 1)
- pose[i][j] = 0;
- ndessous = ndessus = maxdessus = 0;
- applique(n, couvrir);
- handicap_couvrir(n);
- printf("%% %d pierres en pile (hauteur max : %d) sur %d endroits\n",
- ndessus, maxdessus, ndessous);
- }
-
- printf("%%%%Page %d %d\n\nsave\ninitHaut\n", npages, npages + 1);
- npages += 1;
-
- /* titre */
- if (racine->commentaire != 0){
- printf("[ ");
- pschaine(racine->commentaire, "");
- printf(" ] titres\n\n");
- }
-
- /* le goban (ca place aussi les coordoonnees pour le reste) */
- printf("goban\n\n");
-
- /* pierres sur le goban */
- printf("[ ");
- applique(racine, pscoups);
- printf(" ] coups\n\n");
-
- /*
- se debrouiller avec les pierres recouvertes les unes par les autres :
- s'il y en a moins de 18, on peut les placer a droite du goban
- sinon, on traite les repetitions les plus frequentes comme des kos
- */
- if (ndessus != 0){
- extern int kolim;
-
- if (ndessus > 18){
-
- kolim = 3;
- applique(racine, koprep);
- printf("[ ");
- psko();
- printf(" ] kos\n");
- kofin();
- } else
- kolim = maxdessus; /* pas de limite */
-
- printf("[ ");
- applique(racine, pscouvre);
- printf(" ] couvres\n\n");
- }
-
- /* commentaires */
- printf("[ ");
- applique(racine, pscommentaires);
- printf(" ] commentaires\n\n");
-
- printf("\n\nshowpage\n\nrestore\n\n");
- }
-
- /* psfinir -- terminer le traitement d'un fichier */
- psfinir(n) int n; {
- printf("%%%%Pages: %d\n", n);
- }
-
- /* pschaine -- applique psfonc a toutes les lignes contenues dans s */
- pschaine(s, psfonc) char * s, * psfonc; {
- char sauvecar = s[0];
-
- while(sauvecar != 0){
- char * p, * pp;
- /* avance p jusqu'a la fin de la ligne */
- for(p = s; *p != 0 && *p != '\n'; p += 1)
- ;
- sauvecar = *p;
- *p = 0;
- /* ad'hoc : n'affiche pas les lignes qui se terminent par ':' */
- /* recule pp jusqu'au dernier car. */
- for(pp = p - 1; pp != s && *pp == ' '; pp -= 1)
- ;
- if (pp != s && *pp != ':')
- /* fin du ad'hoc */
- printf("(%s) %s\n", s, psfonc);
- s = p + 1;
- }
- }
-
- /*
- Traitement des pierres recouvertes les unes par les autres
- */
- int kolim; /* hauteur de la pile avant de faire un ko */
-
- /* pscouvre -- le cas echeant, affiche le noeud comme "X en Y" */
- pscouvre(n) Noeud * n; {
- if (n->dessous != 0 && n->dessous->ndessus <= kolim)
- printf("[ (%s) %d [ (%s) %d] ]\n",
- nomme(n->dessous), n->dessous->couleur, nomme(n), n->couleur);
- }
-
- /* les piles de pierres pose'es quelquepart */
- struct ko {
- Noeud * dessous; /* qui est dessous */
- int ndessus; /* combien il y en a dessus */
- Noeud ** dessus; /* (les adresses de) ceux qui sont dessus */
- } * kos;
-
- /* koprep -- le cas echeant, empile sur la pile des X en Y */
- koprep(n) Noeud * n; {
- if (n->dessous != 0)
- if (n->dessous->ndessus > kolim){
- Noeud * sous = n->dessous;
- int i;
- /* alloue si necessaire */
- if (kos == 0 && (kos = (struct ko *)calloc(ndessous, sizeof kos[0])) == 0)
- merror();
- for(i = 0; kos[i].dessous != 0; i += 1)
- if (kos[i].dessous == sous)
- break;
- if (kos[i].dessous == 0){
- kos[i].dessous = sous;
- if ((kos[i].dessus
- = (Noeud **)calloc(sous->ndessus, sizeof kos[0].dessus[0])) == 0)
- merror();
- kos[i].ndessus = 0;
- }
- /* ajoute sur la pile */
- kos[i].dessus[kos[i].ndessus++] = n;
- }
- }
-
- /* psko -- affiche les empilements */
- psko(){
- int i, j;
-
- for(i = 0; i < ndessous && kos[i].dessous != 0; i += 1){
- printf("[ (%s) %d [", nomme(kos[i].dessous), kos[i].dessous->couleur);
- for(j = 0; j < kos[i].ndessus; j += 1)
- printf(" (%s) %d", nomme(kos[i].dessus[j]), kos[i].dessus[j]->couleur);
- printf("] ]\n");
- }
- }
-
- /* kofin -- libere la memoire es empilements */
- kofin(){
- if (kos != 0){
- int i;
-
- for(i = 0; i < ndessous; i += 1)
- free(kos[i].dessus);
- free(kos);
- kos = 0;
- }
- }
-
- /* pscoups -- affiche un coup */
- pscoups(n) Noeud * n; {
- if ((n->couleur == BLANC || n->couleur == NOIR) && n->dessous == 0)
- printf("[ (%s) %d %d %d ]\n", nomme(n), n->couleur, n->position.x,
- n->position.y);
- }
-
- /* pscommentaires -- affiche un commentaire, avec son coup */
- pscommentaires(n) Noeud * n; {
- if (n->commentaire != 0 && n != racine){
- printf("[ (%s) %d (%s) ]\n", nomme(n), n->couleur, n->commentaire);
- }
- }
- SHAR_EOF
- fi
- exit 0
- # End of shell archive
-